using System.Linq;
using System.Collections;
using System.Diagnostics;
using System.Collections.Generic;

namespace SilenthinkCommon.Extension
{
    public static class CollectionExtension
    {
        [DebuggerStepThrough]
        public static bool IsNullOrEmpty<T>(this ICollection<T> collection)
        {
            return (collection == null) || (collection.Count == 0);
        }

        [DebuggerStepThrough]
        public static bool IsNullOrEmpty(this IEnumerable iEnumerable)
        {
            if (iEnumerable != null)
            {
                return !iEnumerable.GetEnumerator().MoveNext();
            }
            return true;
        }

        /// <summary>
        /// Determines whether a collection is null or has no elements without having to enumerate the entire collection to get a count.  Uses LINQ.
        /// </summary>
        /// <typeparam name="T">The item type.</typeparam>
        /// <param name="items">The items.</param>
        /// <returns>
        /// <c>true</c> if the collection is null or has no elements; otherwise, <c>false</c>.
        /// </returns>
        [DebuggerStepThrough]
        public static bool IsNullOrEmpty<T>(this IEnumerable<T> items)
        {
            return items == null || !items.Any();
        }
    }
}